package com.lh.java.basic.recurrence;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 ************************************************
 ** Module :  递归
 ** Date: 2012-8-1  Time: 下午05:05:01 
 ** Author lh 
 ************************************************ 
 */
public class RecurrenceTest {
	static int number ;
	public static void main(String[] args) {
		System.out.println("please input a number");
		try {
			number = Integer.parseInt(getString());
		} catch (Exception e) {
		System.out.println("change number error");
		}
		System.out.println(triangle(number));

	}
    
	public static int triangle(int n) {		
		return (n==1?1:(n+triangle(n-1)));
	}
	
	public static String getString() throws IOException {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String s  = br.readLine();
		return s;
		
	}
}
